package fileutil

import (
	"fmt"
	"github.com/h2non/filetype"
	"lib/exception"
	"os"
)

func GetMimeType(sourcePath string) (string, exception.Exception) {
	bytes, readErr := os.ReadFile(sourcePath)
	if readErr != nil {
		return "", exception.NewException(fmt.Sprintf("ReadFileErr. Err is %v.", readErr), 1)
	}
	kind, _ := filetype.Match(bytes)
	if kind == filetype.Unknown {
		return "", exception.NewException(fmt.Sprintf("Unkonwn"), 1)
	}
	return kind.MIME.Value, nil
}
